import math
import graphics


BAR3D_UP_RIGHT = 0
BAR3D_UP_LEFT = 1
BAR3D_DOWN_LEFT = 2
BAR3D_DOWN_RIGHT = 3


def draw_3d_bar(x, y, w, h, d, dir = BAR3D_UP_RIGHT, fill = graphics.DEFAULT_FILL):    
    if dir == BAR3D_DOWN_RIGHT:
        contour = ([w+d, h+d], [d, h+d], [0, h],[0,0], [w, 0], [w+d, d])
        top = [w, h]
        lines = (0, 2, 4)
    elif dir == BAR3D_DOWN_LEFT:
        contour = ([0,0], [w, 0], [w, h], [w-d, h+d], [-d, h+d], [-d, d])
        top = [0, h]
        lines = (0, 2, 4)
    elif dir == BAR3D_UP_LEFT:
        contour = ([-d,-d], [w-d, -d], [w, 0], [w, h], [0, h], [-d, h-d])
        top = [0, 0]
        lines = (0, 2, 4)
    else:
        contour = ([0,0], [d, -d], [w+d, -d], [w+d, h-d], [w, h], [0, h])
        top = [w, 0]
        lines = (0, 2, 4)
    for i in (0,1,2,3,4,5):
        contour[i][0] += x
        contour[i][1] += y
    top[0] += x
    top[1] += y


    graphics.begin()
    graphics.draw_polygon(contour, fill)
    for line in lines:
        c = contour[line]
        graphics.draw_line(top[0], top[1], c[0], c[1])
        
    graphics.end()
    

def draw_regular_polygon(n, x, y, r, phi=0, fill = graphics.DEFAULT_FILL):
    path = []    
    phi *=  (2*math.pi)/360
    a = 2*math.pi/n
    for i in range(n):
        b = phi + i*a
        path.append((int(x + r*math.cos(b)), int(y + r*math.sin(b))))
    graphics.begin()    
    graphics.draw_polygon(path, fill)
    graphics.end()

def draw_star(n, x, y, inner_r, r, inner_phi = 0, phi = 0, fill = graphics.DEFAULT_FILL):
    path = []    
    phi *=  (2*math.pi)/360
    inner_phi *=  (2*math.pi)/360
    a = math.pi/n
    for i in range(n):
        b = phi + 2*i*a
        path.append((int(x + r*math.cos(b)), int(y + r*math.sin(b))))
        b += a + inner_phi
        path.append((int(x + inner_r*math.cos(b)), int(y + inner_r*math.sin(b))))
    graphics.begin()    
    graphics.draw_polygon(path, fill)
    graphics.end()

